import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";

import "element-ui/lib/theme-chalk/index.css";
// 样式重置
import "./assets/style/common.css";
// 富文本编辑器样式
import "./assets/style/style.css";

import * as echarts from "echarts";
Vue.use(ElementUI);
Vue.prototype.$echarts = echarts;

// vue的自定义指令实现权限控制
// 根据后台返回的权限编码 自定义指令
Vue.directive("power", {
    inserted(el, binding, vnode) {
        // el --绑定当前指令的元素
        // binding
        //  binding.value--指令后的值
        console.log(el);
        if (!store.state.user.power) {
            el.disabled = true;
            el.classList.add("is-disabled");
            el.onclick = null;
        }
        if (!store.state.user.power && el.type == "button") {
            console.log(8888);
            el.classList.add("is-disabled");
        }
    },
});

// 路由守卫实现权限控制

router.beforeEach((to, from, next) => {
    if (store.state.user.power) {
        next();
    } else {
        //权限不足
        if (to.name == "admin" || to.name == "student") {
            //
            next("/layout/vip");
        } else {
            next();
        }
    }
});
Vue.config.productionTip = false;
// eventBus 用来组件之间传参
Vue.prototype.$bus = new Vue({});
new Vue({
    router,
    store,
    render: (h) => h(App),
}).$mount("#app");